<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="/assets/libs/kindeditor/themes/default/default.css"/>
    <script charset="utf-8" src="/assets/libs/kindeditor/kindeditor.js"></script>
    <script charset="utf-8" src="/assets/libs/kindeditor/plugins/code/prettify.js"></script>
    <script src="/assets/js/config.js"></script>
    <link rel="stylesheet" type="text/css" href="css/apply.css"/>

    <script type="text/javascript" src="js/design.js"></script>
    <script type="text/javascript" src="js/multiSelect.js"></script>
</head>
<body>
<p id="notice">小提示:用户可以在<span class="red">报告描述区域粘贴</span>word,excel内容，审核人可以 <span style="color: red">下拉
         “<span class="ke-inline-block ke-statusbar-center-icon"></span>”
    动态
    </span>
    控制页面高度,<span style="margin-left: 2px">文件上传请选择图片或pdf格式,多文件上传<span style="color: red">建议转成pdf后上传</span></span>
</p>
<button onclick="printPage()" style="float: right;" id="button">打印</button>
<form id="fm" style="width: 1200px">
    <h2 align=" center" id="title">通用报告申请</h2>
    <p>申请日期： <span id="crtDate"></span></p>
    <table border="1" style="border-collapse: collapse;width: 100%">
        <tr>
            <td>报告标题</td>
            <td><input class="layui-input" name="title"></td>
            <td>附件:</td>
            <td id="annex">
                <button type="button" class="layui-btn" id="test1" onclick="chooseFile()">
                    <i class="layui-icon">&#xe67c;</i>上传文件
                </button>
                <span id="fileName"></span>
            </td>
        </tr>
        <tr>
            <td>姓名</td>
            <td><input class="layui-input" name="userName" readonly></td>
            <td>部门</td>
            <td><input class="layui-input" name="department"></td>
        </tr>
        <tr>
            <td colspan="1"><label>报告描述</label></td>
            <td colspan="4">
                <textarea id="con" name="reason" cols="100" rows="8"
                          style="width:100%;height:200px;visibility:hidden;"></textarea>

            </td>
        </tr>


    </table>
</form>
</body>
<script>
    var editor;
    KindEditor.ready(function (K) {
        editor = K.create('textarea[name="reason"]', {
            resizeType: 1,
            allowFileManager: true,
            items: [],
            afterCreate: function () {
                var autoheight = K.IE ? this.edit.doc.body.scrollHeight : this.edit.doc.body.offsetHeight;  //判断是否是IE，并获取内容高度。
                this.edit.setHeight(autoheight);   //设置高度
                this.sync();
            },
            afterBlur: function () {
                this.sync();
            },
            afterChange: function () {  //输入文字事件
                var autoheight = K.IE ? this.edit.doc.body.scrollHeight : this.edit.doc.body.offsetHeight;  //判断是否是IE，并获取内容高度。
                this.edit.setHeight(autoheight);   //设置高度
            }
        });
        editor.sync();
        prettyPrint();
    });
</script>
<script>
    var annex = "", fileName = "", showReturnButton = true;
    $(function () {
        var id = getUrlParam();
        if (id) {
            drawApprove(id);
            //审批进入
            $("input").prop('readonly', true);
            $("#app").hide();
            $(".layui-layer-btn").hide();
            $.post('/office/flowStepInstance/queryDetail', {id: id}, function (res) {
                if (res.code == 200) {
                    var data = res.obj;
                    drawForm(data, $("#fm"));
                    $("#crtDate").text(formatDate(new Date(data.crtDate)));
                    if (res.obj.annex) {
                        $("#annex").html(`<a href="#" style="color: blue;text-decoration: underline" onclick="showAnnex('${res.obj.annex}')">点击查看</a>`)
                    }
                    editor.html(data.reason.replace(/\n\t/g, ''));
                }
            })
        } else {
            drawAdd();
            var html = ' <button onclick="addExecute()">添加执行人</button>';
            $(html).appendTo("#designButtonList");
            var today = formatDate(new Date())
            $("#crtDate").text(today);
            $("[name='userName']").val(getUserName());
            $("[name='department']").val(getOrgName());
            //渲染流程
            $.post('/office/flowStepTemplate/getTemplateStep', {userId: getUserId(), templateId: 6}, function (res) {
                if (res.code == 200) {
                    if (res.obj) {
                        drawFlowStep(res.obj.flowNodes);
                    }
                }
            })
        }
    })

    function submitForm() {
        var param = getSubmitParam();
        if (param.reason == '') {
            showAlert('请补全报告描述后提交哦');
            return false;
        }
        if (!validateCommonForm()) {
            showAlert("请补全表单详情后提交哦");
            return false;
        }
        if (param.reason.length > 20000) {
            showAlert('发送流程失败，报告内容过长，请转成附件后提交');
            return false;
        }
        param.userId = getUserId();
        param.title = param.title || $("#title").text();
        layer.confirm('确认提交', function (index) {
            var url = "/office/flowWork/addCommonFlow";
            param.annex = annex;
            param.fileName = fileName;
            doSubmit(url, param);
            return false;
        })
    }

    function chooseFile() {
        var input = document.createElement("input");
        input.type = "file";
        input.click(); //代码执行到这里，本地文件选择框便会打开！
        input.onchange = function () {
            cbAnnexFile = input.files[0];
            if (cbAnnexFile.name.indexOf('jpeg') == -1 &&
                cbAnnexFile.name.indexOf('pdf') == -1 &&
                cbAnnexFile.name.indexOf('png') == -1 &&
                cbAnnexFile.name.indexOf('jpg') == -1) {
                showAlert('为了保证手机端可以查看附件,请上传:jpeg,jpg,png,pdf格式的附件');
                return false;
            }
            $("#fileName").text(cbAnnexFile.name);
            layer.confirm('是否确定上传' + cbAnnexFile.name + '?', function (i) {
                var formData = new FormData();
                formData.append("file", cbAnnexFile);
                var result = uploadFile(formData);
                if (result.code == 200) {
                    annex = result.obj.storeName;
                    fileName = result.obj.fileName;
                    showMsg('上传成功');
                    layer.close(i);
                }
            })
        };
    }

    function printPage() {
        window.print();
    }

    var beforePrint = function () {
        $("#button").hide();
        $("#notice").hide();

    };

    var afterPrint = function () {
        $("#button").show();
        $("#notice").show();
    };

    if (window.matchMedia) {   //返回一个新的 MediaQueryList 对象，表示指定的媒体查询字符串解析后的结果。
        var mediaQueryList = window.matchMedia('print');
        mediaQueryList.addListener(function (mql) {
            if (mql.matches) {
                beforePrint();
            } else {
                afterPrint();
            }
        });
    }

    window.onbeforeprint = beforePrint;
    window.onafterprint = afterPrint;

</script>

</html>